<!--
 * @Descripttion: 
 * @Author: yuxi
 * @Date: 2022-09-15 14:58:04
 * @LastEditors: yuxi
 * @LastEditTime: 2023-01-10 17:14:50
-->
<template>
  <div class="map-container">
    <MiningMap :center="center" :zoom="zoom">
      <MiningTiandituLayer :ak="key" @ready="ready"></MiningTiandituLayer>
      <MiningVectorLayer :featureStyle="style">
        <MiningPolygon :feature="feature"></MiningPolygon>
      </MiningVectorLayer>
    </MiningMap>
  </div>
</template>

<script>
import MiningMap from 'mining-map/Map'
import MiningTiandituLayer from 'mining-map/Layers/TiandituLayer'
import MiningVectorLayer from 'mining-map/Layers/VectorLayer'
import MiningPolygon from 'mining-map/Features/Polygon';
import { TiandituKey, CityCoordinates } from '@/config/config.js';

import Feature from 'ol/Feature';
import Polygon from 'ol/geom/Polygon';
import { Style, Stroke as StrokeStyle, Fill as FillStyle } from 'ol/style';



export default {
  name: 'FeaturePolygon',
  title: 'Polygon',
  parentTitle: 'Feature',
  components: {
    MiningMap,
    MiningTiandituLayer,
    MiningVectorLayer,
    MiningPolygon,
  },
  data () {
    const feature = new Feature({
      type: 'Polygon',
      geometry: new Polygon([[
        // CityCoordinates.BeiJing,
        CityCoordinates.TianJin,
        CityCoordinates.ShangHai,
        CityCoordinates.XiAn
      ]]),
      name: 'AirLine',
    });

    const style = new Style({
      stroke: new StrokeStyle({
        color: 'blue',
        lineDash: [4],
        width: 3,
      }),
      fill: new FillStyle({
        color: 'rgba(0, 0, 255, 0.1)',
      }),
    }) 
    return {
      feature,
      style, 
      center: [117.730311, 35.698681],
      zoom: 5,
      key: TiandituKey,
    }
  },
  methods: {
    ready (arg) {
      console.log(arg)
    }
  }

}
</script>

<style>
body,
html {
  padding: 0;
  margin: 0;
}

.map-container {
  width: 100%;
  height: 100vh;
}
</style>